import {
  savePhoto_share
} from "../../utils/save_share_pic"
import {
  imageUrl
} from "../../utils/imageutil.js"
Component({

  properties: {
    show: {
      type: Boolean,
      value: false
    },
    uid:{
      type:String,
      value:'',
    }
  },


  data: {
    imageUrl,
    userInfo: wx.getStorageSync('userInfo'),
    code: '',
    code_pic: '',
    imgList: [],
    img_curr: 0,
  },

  lifetimes: {
    ready: function () {
      this.getUserGenerateCode()
    },
  },

  methods: {
    getUserGenerateCode() {
      getApp().globalData.post({
        data: {
          do: 'UserGenerateCode',
          uid: this.data.uid,
        }
      }).then(res => {
        this.setData({
          code: res.data.result.code,
          code_pic: "data:image/jpg;base64," + res.data.result.img_url.replace(/[\r\n]/g, ''),
          imgList: res.data.result.list,
        })
      })
    },
    open() {
      this.setData({
        show: true
      })
    },
    close() {
      this.setData({
        show: false
      })
    },
    change_img_curr(e) {
      this.setData({
        img_curr: e.detail.current
      })
    },
    getUserProfile() {
      getApp().showModal('请先授权用户信息').then(() => {
        wx.navigateTo({
          url: '/pages/index/get_wx_info',
        })
      })
    },
    bottomTap() {
      let that = this;
      if (!this.data.userInfo.img || this.data.userInfo.name == "微信用户") {
        this.getUserProfile()
        return;
      }
      wx.getSetting({
        success(res) {
          if (res.authSetting['scope.writePhotosAlbum'] == false) {
            wx.openSetting();
          } else if (res.authSetting['scope.writePhotosAlbum'] == true) {
            savePhoto_share("myCanvas", that, that.data.imgList[that.data.img_curr].pic, that.data.code_pic, that.data.imgList[that.data.img_curr].logo, that.data.imgList[that.data.img_curr].name, that.data.code)
          } else {
            savePhoto_share("myCanvas", that, that.data.imgList[that.data.img_curr].pic, that.data.code_pic, that.data.imgList[that.data.img_curr].logo, that.data.imgList[that.data.img_curr].name, that.data.code)
          }
        },
      })
    },
  },

})